﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace teach
{
    public partial class FormUsers : Form
    {
        private Button[] usersButtons;
        public delegate void UserSelectedHandler(string user);
        public event UserSelectedHandler UserSelected;

        public FormUsers(Dictionary<string, User> users)
        {
            usersButtons = new Button[users.Count];
            InitializeComponent();

            this.SuspendLayout();
            this.Width = 148 * users.Count;

            int idx = 0;
            int xpos = 23; 
            int xposInc = 158 - 23;

            foreach(string user in users.Keys)
            {
                usersButtons[idx] = new Button();
                usersButtons[idx].Location = new System.Drawing.Point(xpos, 12);
                usersButtons[idx].Size = new System.Drawing.Size(107, 88);
                usersButtons[idx].Click += new System.EventHandler(this.btnUser_Click);
                usersButtons[idx].Tag = user;
                usersButtons[idx].Image = users[user].UserImage;

                this.Controls.Add(usersButtons[idx]);
                xpos += xposInc;
                idx++;
            }

            //btnUser1.Image = users["Philippe"].UserImage;
            //btnUser2.Image = users["Simon"].UserImage;
            //btnUser1.Refresh();
            //btnUser2.Refresh();
            this.ResumeLayout();
        }

        private void btnUser_Click(object sender, EventArgs e)
        {
            Button senderButton = sender as Button;
            UserSelected(senderButton.Tag.ToString());
        }

        //private void btnUser1_Click(object sender, EventArgs e)
        //{
        //    UserSelected("Philippe");
        //}

        //private void btnUser2_Click(object sender, EventArgs e)
        //{
        //    UserSelected("Simon");
        //}
    }
}
